package com.github.bobjoy.java.desginpattern;

/**
 * 装饰器模式
 */
public class DecoratorDemo {
    public static void main(String[] args) {
        Sourceable sourceable = new Decorator(new Source());
        sourceable.method();
    }
}

interface Sourceable {
    void method();
}

class Source implements Sourceable {
    @Override
    public void method() {
        System.out.println("this source method");
    }
}

class Decorator implements Sourceable {

    private Sourceable sourceable;

    public Decorator(Sourceable sourceable) {
        this.sourceable = sourceable;
    }

    @Override
    public void method() {
        System.out.println("before method");
        sourceable.method();
        System.out.println("after method");
    }
}